<?php
	$_products = $this->getProductCollection();
	$_helper = $this->helper('catalog/output');
	
	$limitproduct = $this->getLimitCount();
	$size = $_products->getSize();
	if($limitproduct == "" || $limitproduct > $size){
		$limitproduct = $size;
	}
	
	$w = $this->getThumbnailWidth();
	$h = $this->getThumbnailHeight();
	$_columnCount = $this->getColumnCount();
	$alt_img = $this->getAltImg();
	   
	/* slider config */
	$idJs = "em_minifilter_products_".md5(uniqid(rand()));    
	   if ($this->getData('slider_unique_id'))
		$idJs = $this->getData('slider_unique_id');
	$this->idJs = $idJs;
?>
<div id="<?php echo $idJs;?>" class="em-grid-21 <?php if($this->getCustomClass()): ?><?php echo $this->getCustomClass();?><?php endif; ?>">
	<?php if($this->getFrontendTitle()): ?>
		<div class="widget-title em-widget-title">
			<h3><span><?php echo $this->getFrontendTitle(); ?></span></h3>
		</div>
	<?php endif; ?>
    
	<?php if($this->getFrontendDescription()):?>
	<div class="desc"><?php echo $this->getFrontendDescription(); ?></div>
	<?php endif ?>
    
	<?php if ($limitproduct): ?>
	<div class="widget em-filterproducts-grid em-filterproducts-custom">
		<div class="em-inner-product row">			
				<?php $i=0; foreach ($_products as $_product): ?>
                    <?php if($i==0):?>
                        <div class="col-sm-9 em-item-big em-item-left products-grid">
							<div class="item">
								<div class="product-item">
									<div class="product-shop-top">
										<?php if ($this->getShowFrontend('thumb')): ?>
											<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image ">
												<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
												<!--show label product - label extension is required-->
												<?php Mage::helper('productlabels')->display($_product);?>
												<?php endif;?>
												
												<?php if ($alt_img): ?>                            
												<img class="em-alt-hover img-responsive <?php if($this->getData('img_lazyload')): ?>em-img-lazy<?php endif;?>" <?php if($this->getData('img_lazyload')): ?>src="<?php echo $this->getSkinUrl('images/loading.gif') ?>" data-original="<?php echo $this->helper('catalog/image')->init($_product, $alt_img)->resize($w,$h) ?>"<?php else:?>src="<?php echo $this->helper('catalog/image')->init($_product, $alt_img)->resize($w,$h) ?>"<?php endif;?> width="<?php echo $w; ?>" height="<?php echo $h ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
												<?php endif ?>
												<img class="img-responsive <?php if($this->getData('img_lazyload')): ?>em-img-lazy<?php endif;?> <?php if ($alt_img): ?>em-alt-org<?php endif ?>" <?php if($this->getData('img_lazyload')): ?>src="<?php echo $this->getSkinUrl('images/loading.gif') ?>" data-original="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w,$h) ?>"<?php else:?>src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w,$h) ?>"<?php endif;?> width="<?php echo $w; ?>" height="<?php echo $h ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />                        
											</a>
										<?php else: ?>
											<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
											<!--show label product - label extension is required-->
											<?php Mage::helper('productlabels')->display($_product);?>
											<?php endif;?>
										<?php endif; ?>
										<div class="em-element-display-hover bottom">
											<?php if($this->getShowFrontend('addtocart') || $this->getShowFrontend('addto')): ?>
												<div class="em-btn-addto">
													<!--product add to cart-->
													<?php if ($this->getShowFrontend('addtocart')):?>
													<?php if ($_product->isSaleable()): ?>
													<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
													<?php else: ?>
													<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
													<?php endif; ?>
													<?php endif; ?>
													<!--product add to compare-wishlist-->
													<?php if($this->getShowFrontend('addto')):?>
													<ul class="add-to-links">
														<?php if ($this->helper('wishlist')->isAllow()) : ?>
														<li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist" title="<?php echo $this->__('Add to Wishlist') ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
														<?php endif; ?>
														<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
														<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare" title="<?php echo $this->__('Add to Compare') ?>"><?php echo $this->__('Add to Compare') ?></a></li>
														<?php endif; ?>
													</ul>
													<?php endif; ?>
												</div>
											<?php endif;?>
                                            <?php if(Mage::helper('core')->isModuleEnabled('EM_Quickshop') && Mage::helper('quickshop')->getConfig('enable')): ?>
											<div class="quickshop-link-container hidden-xs">
												<a href="<?php echo Mage::helper('quickshop/links')->addQuickShopLink($_product->getProductUrl()); ?>" class="quickshop-link" title="<?php echo $this->__('Product Quick View: ') ?><?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Quickshop') ?></a>
											</div>
                                            <?php endif;?>
										</div>
									</div>
									<div class="product-shop">
										<div class="f-fix">
											<!--product name-->
											<?php if ($this->getShowFrontend('name')):?>
											<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h3>
											<?php endif;?>
											<?php if ($this->getShowFrontend('sku')):?>
											<p class="sku"><?php echo $_product->getSku(); ?></p>
											<?php endif ;?>
											<!--product description-->
											<?php if ($this->getShowFrontend('desc')):
												$desc = $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description');
												if(strlen($desc)>80) {
													$strCutTitle = substr($desc, 0, 80);
													$desc = substr($strCutTitle, 0, strrpos($strCutTitle, ' '));
												}
											?>
											<p class="desc"><?php echo $desc; ?></p>
											<?php endif ;?>
											<!--product reviews-->
											<?php if ($this->getShowFrontend('review')):?>
											<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
											<?php endif ; ?>
											<!--product price-->
											<?php if ($this->getShowFrontend('price')):?>
												<?php if (Mage::helper('catalog')->canApplyMsrp($_product)):?>
													<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Detail') ?></a>
												<?php else : ?>
													<?php echo $this->getPriceHtml($_product, true, "-emprice-".md5(uniqid(rand())) ) ?>
												<?php endif;?>
											<?php endif;?>
										</div>
										</div>
										<?php 
											$_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages();
											$_wThumbs = $w/4 - 10;
											$_hThumbs = $h/4 - 10; 
										?>    
										
										<?php if (count($_images) > 0): ?>
										<div class="em-more-views row">
											<?php $j=0; foreach ($_images as $_image): ?>
											<?php 
												$_img_big = (string)$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile()); 
												$_img_thumb = (string)$this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize($_wThumbs,$_hThumbs); 
											?>
												<div class="col-sm-8" >
													<a class="em-thumb em_lightbox_<?php echo $idJs.$i?>" rel="gallery_<?php echo $idJs.$i?>" href="<?php echo $_img_big ?>#image<?php echo $idJs.$i ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
														<img class="img-responsive" src="<?php echo $_img_thumb ?>"  width="<?php echo $_wThumbs; ?>" height="<?php echo $_hThumbs ?>" alt="<?php echo $this->escapeHtml($_image->getLabel()) ?>"  />
													</a>
												</div>
											<?php if($j>=2) break;?>
											<?php $j++;?>
											<?php endforeach; ?>

										</div>
										<script type="text/javascript">
										//<![CDATA[						    
												jQuery(".em_lightbox_<?php echo $idJs.$i ?>").fancybox({									
													margin: [20, 40, 20, 10],
													scrolling : 'no',
													type : 'image',
													nextEffect : 'none',
													prevEffect : 'none',
												});							
										//]]>
										</script>
										<?php endif; ?>
									
								</div>
                            </div>
        				</div>
                    <?php else:?>
                        <?php if($i==1):?>
                        <div class="col-sm-15 em-item-right products-grid">
						<div class="row">
                        <?php endif;?>
                            <div class="col-xs-12 col-sm-8 <?php if($itemClass = $this->getData('item_class')) echo $itemClass.' '; ?>item<?php echo $_columnCount > 0 && $i%$_columnCount==0 || $_columnCount <= 0 && $i == 0 ?' first':''; ?><?php echo $_columnCount > 0 && ($i+1)%$_columnCount==0 || $i+1 == $limitproduct ?' last':''; ?>"
            					style="<?php echo $this->getItemWidth() ? 'width:'.$this->getItemWidth().'px;' : '' ?> <?php echo $this->getItemHeight() ? 'height:'.$this->getItemHeight().'px;' : '' ?> <?php echo $this->getItemSpacing() ? 'margin-right:'.$this->getItemSpacing().'px;' : '' ?>">
                                <div class="product-item">
                                    <div class="product-shop-top">
                    					<?php if ($this->getShowFrontend('thumb')): ?>
                        					<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image ">
                        						<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
                        						<!--show label product - label extension is required-->
                        						<?php Mage::helper('productlabels')->display($_product);?>
                        						<?php endif;?>
                                                
                        						<?php if ($alt_img): ?>                            
                                                <img class="em-alt-hover img-responsive <?php if($this->getData('img_lazyload')): ?>em-img-lazy<?php endif;?>" <?php if($this->getData('img_lazyload')): ?>src="<?php echo $this->getSkinUrl('images/loading.gif') ?>" data-original="<?php echo $this->helper('catalog/image')->init($_product, $alt_img)->resize($w/2,$h/2) ?>"<?php else:?>src="<?php echo $this->helper('catalog/image')->init($_product, $alt_img)->resize($w/2,$h/2) ?>"<?php endif;?> width="<?php echo $w/2; ?>" height="<?php echo $h/2 ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
                        						<?php endif ?>
                        						<img class="img-responsive <?php if($this->getData('img_lazyload')): ?>em-img-lazy<?php endif;?> <?php if ($alt_img): ?>em-alt-org<?php endif ?>" <?php if($this->getData('img_lazyload')): ?>src="<?php echo $this->getSkinUrl('images/loading.gif') ?>" data-original="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w/2,$h/2) ?>"<?php else:?>src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w/2,$h/2) ?>"<?php endif;?> width="<?php echo $w/2; ?>" height="<?php echo $h/2 ;?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />                        
                        					</a>
                    					<?php else: ?>
                        					<?php if ($this->getShowFrontend('label') && Mage::helper('core')->isModuleEnabled('EM_Productlabels')):?>
                        					<!--show label product - label extension is required-->
                        					<?php Mage::helper('productlabels')->display($_product);?>
                        					<?php endif;?>
                    					<?php endif; ?>
                                        <div class="em-element-display-hover bottom">
                                            <?php if($this->getShowFrontend('addtocart') || $this->getShowFrontend('addto')): ?>
                                                <div class="em-btn-addto">
                        							<!--product add to cart-->
                        							<?php if ($this->getShowFrontend('addtocart')):?>
                        							<?php if ($_product->isSaleable()): ?>
                        							<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                        							<?php else: ?>
                        							<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                        							<?php endif; ?>
                        							<?php endif; ?>
                        							<!--product add to compare-wishlist-->
                        							<?php if($this->getShowFrontend('addto')):?>
                        							<ul class="add-to-links">
                        								<?php if ($this->helper('wishlist')->isAllow()) : ?>
                        								<li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist" title="<?php echo $this->__('Add to Wishlist') ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        								<?php endif; ?>
                        								<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                        								<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare" title="<?php echo $this->__('Add to Compare') ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                        								<?php endif; ?>
                        							</ul>
                        							<?php endif; ?>
                                                </div>
                                            <?php endif;?>
                                            <div class="quickshop-link-container hidden-xs">
                                                <a href="<?php echo Mage::helper('quickshop/links')->addQuickShopLink($_product->getProductUrl()); ?>" class="quickshop-link" title="<?php echo $this->__('Product Quick View: ') ?><?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Quickshop') ?></a>
                                            </div>
                                        </div>
                                    </div>
                					<div class="product-shop">
                						<div class="f-fix">
                							<!--product name-->
                							<?php if ($this->getShowFrontend('name')):?>
                							<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h3>
                							<?php endif;?>
                							<?php if ($this->getShowFrontend('sku')):?>
                							<p class="sku"><?php echo $_product->getSku(); ?></p>
                							<?php endif ;?>
                							<!--product description-->
                							<?php if ($this->getShowFrontend('desc')):
                								$desc = $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description');
                								if(strlen($desc)>80) {
                									$strCutTitle = substr($desc, 0, 80);
                									$desc = substr($strCutTitle, 0, strrpos($strCutTitle, ' '));
                								}
                							?>
                							<p class="desc"><?php echo $desc; ?></p>
                							<?php endif ;?>
                							<!--product reviews-->
                							<?php if ($this->getShowFrontend('review')):?>
                							<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                							<?php endif ; ?>
                							<!--product price-->
                							<?php if ($this->getShowFrontend('price')):?>
                								<?php if (Mage::helper('catalog')->canApplyMsrp($_product)):?>
                									<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->__('Detail') ?></a>
                								<?php else : ?>
                									<?php echo $this->getPriceHtml($_product, true, "-emprice-".md5(uniqid(rand())) ) ?>
                								<?php endif;?>
                							<?php endif;?>
                						</div>
                					</div>
                                </div>
            				</div>
                        <?php if($i>=$limitproduct):?>
                        </div> 
                        </div> 
                        <?php endif;?>        				                           
                    <?php endif;?>
				
				<?php $i++;?>
				<?php if($i >= $limitproduct) break;?>
				<?php endforeach; ?>
			</div>			
		</div>
	</div>
</div>
<?php else:?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php endif; ?>
